#!/bin/bash
#IModule

#########################
#   名称: SimpleCM
#   用途: 提供简单的读写功能
#   全称: SimpleConfigManager
#########################

#配置文件
if [ -z "$_SimpleCM_Loaded" ];then
    function _framework_resolve_dependencies()
    {
        true;
    }

    echo "${_framework_ROOT:?}" > /dev/null;
    export _SimpleCM_File="_SimpleCM.ini";
    readonly _SimpleCM_CONFIG_NAMESPACE="$(basename "${BASH_SOURCE:-$0}")";
    #shellcheck disable=SC1090
    source "$_framework_ROOT/modules/IniConfig";

    function _SimpleCM_ChangeTargetFile()
    {
        local file="$1";
        if [ -z "$file" ];then
            return 1;
        elif [ ! -f "$file" ] && [ ! -d "$file" ];then
            export _SimpleCM_File="$file";
            touch "$file";
        elif [ -f "$file" ];then
            export _SimpleCM_File="$file";
            return 0;
        else
            return 2;
        fi;
    }

    function _SimpleCM_InitConfigFile()
    {
        if [ ! -f "$_SimpleCM_File" ];then
            touch "$_SimpleCM_File";
        fi;
        #在这条注释下面添加代码
    }

    function _SimpleCM_GetValue()
    {
        local key="$1";
        local value="";

        if value="$(_IniConfig_ReadOptionFromFile "$_SimpleCM_File" "$_SimpleCM_CONFIG_NAMESPACE" "$key")";then
            echo "$value";
        else
            return 1;
        fi;
    }

    function _SimpleCM_SetValue()
    {
        local key="$1";
        local value="$2";

        if [ -z "$key" ] || [ -z "$value" ];then
            return 1;
        fi;

        _IniConfig_WriteOptionToFile "$_SimpleCM_File" "$_SimpleCM_CONFIG_NAMESPACE" "$key" "$value";
    }

    readonly _SimpleCM_Loaded=true;
fi;